array element
The elements of an array are variables, and are used in expressions just like normal
variables, as in the following examples:
FUNCTION Demo (w, x, y, z$)
SHARED a%[]
'
a%[] has SHARED scope
SHARED k[]
'
k[] has SHARED scope
STATIC j$[]
'
j$[] has STATIC scope
IFZ j$[] THEN DIM j$[63] ' DIM j$[] on first entry
a%[w] = x
'
wth element of a%[] = x
k[z] = x * a%[w] * a%[y] ' use arrays in an expression
j$[x] = z$
'
put a string in j$[x]
END FUNCTION
array implementation
One-dimensional arrays are implemented as a contiguous set of elements, much like other
languages. Multi-dimensional arrays, however, are implemented as multi-level trees
of one-dimensional arrays. As long as they are created and used in the conventional
manner, this implementation difference is invisible. But tree-structure arrays have
enormous advantages.
tree structure
Multi-dimensional arrays are arrays of array addresses, except for the lowest dimension
which contains data. This permits the construction of irregular arrays, for which
there are supporting features.
regular array
There's no difference between conventional vs tree structure, or regular vs irregular in
one dimensional arrays. And multi-dimensional arrays behave just like conventional
arrays as long as the features provided to create and manipulate irregular arrays are not
employed.
irregular array
The distinction between regular and irregular arrays applies only to multi-dimensional
arrays. Furthermore, irregular arrays need not be built or manipulated until and
unless their special properties are needed. Many programmers may never need them.
On the other hand, system programs, and other sophisticated applications are often
vastly more efficient and easier to implement with irregular arrays.
Regular arrays have the same number of elements in every instance of a given dimension.
In an array created by DIM a[3,7], the upper bound of the low dimension is 7 for
all three upper dimension values (a[0,7] , a[1,7] , a[2,7], a[3,7]). Regular arrays
can be thought of as rectangular.
Irregular arrays don't need to have the same number of elements in every instance of a
given dimension. For example, the upper bounds of the low dimension of a similar
irregular array could be b[0,3] , b[1,*] , b[2,5] , b[3,2] (where "*" means no
elements are allocated in this subdimension). Therefore, irregular arrays cannot be
thought of as rectangular, but can be thought of as ragged arrays.
nodes and data
Arrays contain two kinds of contents, nodes and data. Elements in the lowest dimension are
data. Elements in higher dimensions are nodes, meaning addresses of sub-arrays.
Consider a[], created by DIM a[3,7] . Five one-dimensional arrays are created.
The first array corresponds to the higher dimension, a[3, ], and contains elements
0 to 3. These elements are nodes, addresses of four arrays that contain data
elements 0 to 7.